#!/usr/bin/python
# -*- coding: utf-8 -*-
#database tool
import dbOperate
import collections
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
#file_dict = {}
file_dict = collections.OrderedDict()
db1 = dbOperate.dbOperate('10.37.133.21', 'spider', 'spider', 'spider')
# db => dict
def getequip():
    sql = 'select * from equip '  # sql语句
    see = db1.exe_query(sql)  # 使结果全部可看
    file_dict = collections.OrderedDict()
    ####遍历see
    for data in see:
        if data:
            file_dict[data[0]] = data[1]

    # print('person--------' + str(file_dict))
    return file_dict

# ditc => db
def equip_write():

    for user, pwd in file_dict.items():
        sql = 'update equip set count = ' + '"' + pwd + '"' + ' where name = ' + '"' + user + '"'
        # print(sql)
        db1.exe_query(sql)

#delete方法
def file_del(para):
    #file_arr = []
    sql = 'delete FROM duty where weekday =  ' + '"' + para + '"'
    # print(sql)
    db1.exe_query(sql)
def file_ins(para1,para2):
    sql = 'INSERT INTO duty (`weekday`, `person`) VALUES (' + '"' + para1 + '"' + ',' +'"' + para2 + '"' +')'
    # print(sql)
    db1.exe_query(sql)

if __name__ == "__main__":
    # print(getequip())
    getequip()